﻿/*
 * Terminal.java
 *
 * Created on 2007年5月29日, 下午 1:20
 *
 *
 
 */

package org.uranus.core.terminal;


import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.TextField;
import org.uranus.core.dataHandler.HostInfoData;
import org.uranus.core.ssh.SshIO;
import org.uranus.core.telnet.Telnet;
import org.uranus.core.uitl.StringTokenizer;
import org.uranus.mainGUI.GUI;


/**
 * Copyright 2007 Hsiang-Yu Wang<br>
 * This file is distributed under the terms of the GNU General Public License<br>
 *<br>
 *<pre>
 * --------------------License notice--------------------
 * GNU GENERAL PUBLIC LICENSE
 * Version 3, 29 June 2007
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not,
 * visit: http://www.gnu.org/licenses/gpl.txt
 * --------------------License notice--------------------</pre>
 *
 * @author Hsiang-Yu Wang
 */
/**
 * 模擬所有Terminal行為之class
 *
 */
public class Terminal extends Canvas implements CommandListener{
    public  int width, height, fontWidth, fontHeight;
    
    private Font font;
    
    private int basePosX = 0;
    private int basePosY = 0;
    
    private int protocol;  // 1 for ssh, 0 for telnet
    
    private ANSI ansi;
    private Telnet telnet;
    private SshIO ssh;
    private TerminalFont[][] screen;
    
    private boolean keyPressSwitch = true;    //  Lock the axis moving if is true
    private boolean inputLock = false;
    private StringTokenizer st;
    
    /** UI items **/
    private Command exitCmd;
    private Command inputCmd;
    private Command key_SpaceCmd;
    private Command key_EnterCmd;
    private Command inputFormSendCmd;
    private Command ctrlFormSendCmd;
    private Command altFormSendCmd;
    private Command inputFormExitCmd;
    private Command ctrlFormExitCmd;
    private Command altFormExitCmd;
    private Command key_BackSpaceCmd;
    private Form inputForm;
    private Form ctrlForm;
    private Form altForm;
    private Form sshLogin;
    private TextField inputFormTF;
    private TextField ctrlFormTF;
    private TextField altFormTF;
    private TextField sshLogin_pwdTF;
    private GUI gui;
    private Command spaceCmd;
    private Command backspaceCmd;
    private Command tabCmd;
    private Command delCmd;
    private Command page_upCmd;
    private Command page_downCmd;
    private Command ctrlCmd;
    private Command altCmd;
    private Command disconnectCmd;
    private Command okCommand7;
    private Command sshLogin_backCmd;
    
    private HostInfoData hostInfo;
    private SshIO sshIO;
    
    private final int KEY_UP = -1;
    private final int KEY_DOWN = -2;
    private final int KEY_LEFT = -3;
    private final int KEY_RIGHT = -4;
    
    private final int ESC = 0x1B;
    private final int ascii_A = 0x41;
    private final int ascii_B = 0x42;
    private final int ascii_C = 0x43;
    private final int ascii_D = 0x44;
    private final int ascii_E = 0x45;
    private final int ascii_F = 0x46;
    private final int ascii_G = 0x47;
    private final int ascii_H = 0x48;  //
    private final int ascii_I = 0x49;
    private final int ascii_J = 0x4A;   //
    private final int ascii_K = 0x4B;
    private final int ascii_L = 0x4C;
    private final int ascii_M = 0x4D;
    private final int ascii_N = 0x4E;
    private final int ascii_O = 0x4F;
    private final int ascii_P = 0x50;
    private final int ascii_Q = 0x51;
    private final int ascii_R = 0x52;
    private final int ascii_S = 0x53;
    private final int ascii_T = 0x54;
    private final int ascii_U = 0x55;
    private final int ascii_V = 0x56;
    private final int ascii_W = 0x57;
    private final int ascii_X = 0x58;
    private final int ascii_Y = 0x59;
    private final int ascii_Z = 0x5A;
    private final int LEFT_BRACKET = 0x5B;
    private final int ascii_a = 0x61;
    private final int ascii_b = 0x62;
    private final int ascii_c = 0x63;
    private final int ascii_d = 0x64;
    private final int ascii_e = 0x65;
    private final int ascii_f = 0x66;
    private final int ascii_g = 0x67;
    private final int ascii_h = 0x68;
    private final int ascii_i = 0x69;
    private final int ascii_j = 0x6A;
    private final int ascii_k = 0x6B;
    private final int ascii_l = 0x6C;
    private final int ascii_m = 0x6D;  //
    private final int ascii_n = 0x6E;
    private final int ascii_o = 0x6F;
    private final int ascii_p = 0x70;
    private final int ascii_q = 0x71;
    private final int ascii_r = 0x72;
    private final int ascii_s = 0x73;
    private final int ascii_t = 0x74;
    private final int ascii_u = 0x75;
    private final int ascii_v = 0x76;
    private final int ascii_w = 0x77;
    private final int ascii_x = 0x78;
    private final int ascii_y = 0x79;
    private final int ascii_z = 0x80;
    
    /**
     *  僅做所有初始化動作
     **/
    public Terminal(){
        width = super.getWidth();
        height = super.getHeight();
        
        font = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_PLAIN,font.SIZE_MEDIUM);
        
        fontHeight = font.getHeight()  - 7;
        
        screen = new TerminalFont[24][80];
        
        this.addCommand(this.getExitCmd());
        this.addCommand(this.getInputCmd());
        this.addCommand(this.getKey_SpaceCmd());
        this.addCommand(this.getKey_EnterCmd());
        this.addCommand(this.getKey_BackSpaceCmd());
        this.addCommand(this.getSpaceCmd());
        this.addCommand(this.getBackSpaceCmd());
        this.addCommand(this.getTabCmd());
        this.addCommand(this.getDelCmd());
        this.addCommand(this.getPage_UpCmd());
        this.addCommand(this.getPage_DownCmd());
        this.addCommand(this.getCtrlCmd());
        this.addCommand(this.getAltCmd());
        this.addCommand(this.getDisconnectCmd());
        this.setCommandListener(this);
    }
    
    
    protected synchronized void keyLock(){
        keyPressSwitch = true;
    }
    
    public synchronized void inputLock(){
        inputLock = !inputLock;
    }
    /**
     *   處理screen[][]中的資訊
     *   因中文字與英文字寬度不同, 此method會做到寬度補償的效果
     *
     *   @param g
     *
     **/
    protected void paint(Graphics g){
        synchronized(screen){
            g.setColor(0x000000);
            g.fillRect(0,0,width,height);
            
            int baseX = 0;
            int baseY = 0;
            
            if(protocol == 1 && keyPressSwitch){
                if(ansi.getCursorPosY() > 24){
                    basePosY = ansi.getCursorPosY() - 24;
                }
            }
            for(int i = basePosY ; (i < screen.length || i < basePosY + 24) ; i++){
                for(int j = basePosX ; j < screen[i].length ; j++){
                    if(screen[i][j] == null || (screen[i][j].isPadding() && j - basePosX != 0))
                        continue;
                    /** 將中文字的padding排除顯示**/
                    
                    fontWidth = (screen[i][j].isTwoBytes())? 10:5;
                    switch(screen[i][j].getType()){
                        case 0:
                            resetAll();
                            break;
                        case 3:
                            italicOn();
                            break;
                        case 4:
                            underScore();
                            break;
                    }
                    
                    g.setFont(font);
                    g.setColor(screen[i][j].getBgcolor());
                    g.fillRect(baseX, baseY, fontWidth, fontHeight);
                    g.setColor(screen[i][j].getFgcolor());
                    g.drawChar(screen[i][j].getText(),baseX , baseY - 3, 0);
                    baseX += fontWidth;
                    
                }
                baseY += fontHeight;
                baseX = 0;
                
            }
            keyPressSwitch = false;
            System.gc();
        }
    }
    private void resetAll(){
        font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
    }
    private void underScore(){
        font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_UNDERLINED, Font.SIZE_MEDIUM);
    }
    private void boldOn(){
        font = Font.getFont( Font.FACE_MONOSPACE,
                Font.STYLE_BOLD, Font.SIZE_MEDIUM );
    }
    
    private void italicOn(){
        font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_SMALL);
        
    }
    public void setScreen(TerminalFont[][] screen){
        this.screen = screen;
    }
    
    
    /**
     *  Starting a terminal
     *
     *  @param setting
     *         a parameter where it has all information of this connection.
     *  @see Settings
     *  @see Telnet
     */
    public void startTerminal(HostInfoData hostInfo){
        this.protocol = (hostInfo.getProtocol().equals("SSH"))? 1 : 0;
        
        if(protocol == 0){
            telnet = new Telnet();
            telnet.setIP(hostInfo.getAddress(), hostInfo.getPort());
            
            telnet.start(); // Starting TELNET THREAD
            
            ansi = telnet.getAnsi();
            
        }else if(protocol == 1){
            ssh = new SshIO(hostInfo);
            ssh.start();
            ansi = ssh.getAnsi();
        }
    }
    /**
     *     Starting repaint buffer
     *
     *     @see #bufferCheck
     *     @see #resetBuffer
     **/
    public void startingBuffer(boolean b){
        
    }
    
    /**
     *    檢查buffer是否滿載, 如buffer中character已超過10個charactersreturn true, and vice versa.
     *
     *     @see #resetBuffer
     *     @see #startingBuffer
     **/
    public boolean bufferCheck(String in){
        return true;
    }
    /**
     *   Reset all buffer counter
     *
     *    @see #bufferCheck
     *    @see #startingBuffer
     **/
    public void resetBuffer(){
        
    }
    
    public Command getExitCmd() {
        exitCmd = (exitCmd == null)? new Command("Exit", Command.EXIT,1) : exitCmd;
        return exitCmd;
    }
    
    public Command getInputCmd() {
        inputCmd = (inputCmd == null)? new Command("Input", Command.OK,1) : inputCmd;
        return inputCmd;
    }
    
    public Command getKey_SpaceCmd() {
        key_SpaceCmd = (key_SpaceCmd == null)? new Command("KEY_SPACE", Command.OK,3) : key_SpaceCmd;
        return key_SpaceCmd;
    }
    
    public Command getKey_EnterCmd() {
        key_EnterCmd = (key_EnterCmd == null)? new Command("KEY_Enter", Command.OK,2) : key_EnterCmd;
        return key_EnterCmd;
    }
    
    private Command getKey_BackSpaceCmd(){
        key_BackSpaceCmd = (key_BackSpaceCmd == null)? new Command("KEY_BackSpace", Command.OK,2) : key_BackSpaceCmd;
        return key_BackSpaceCmd;
    }
    
    public Command getSpaceCmd(){
        spaceCmd = (spaceCmd == null)? new Command("Space", Command.OK,2) : spaceCmd;
        return spaceCmd;
    }
    
    public Command getBackSpaceCmd(){
        backspaceCmd = (backspaceCmd == null)? new Command("BackSpace", Command.OK,2) : backspaceCmd;
        return backspaceCmd;
    }
    
    public Command getTabCmd(){
        tabCmd = (tabCmd == null)? new Command("Tab", Command.OK,2) :tabCmd;
        return tabCmd;
    }
    
    public Command getDelCmd(){
        delCmd = (delCmd == null)? new Command("Delete", Command.OK,2) :delCmd;
        return delCmd;
    }
    
    public Command getPage_UpCmd(){
        page_upCmd = (page_upCmd == null)? new Command("Page Up", Command.OK,2) :page_upCmd;
        return page_upCmd;
    }
    
    public Command getPage_DownCmd(){
        page_downCmd = (page_downCmd == null)? new Command("Page Down", Command.OK,2) :page_downCmd;
        return page_downCmd;
    }
    
    public Command getCtrlCmd(){
        ctrlCmd = (ctrlCmd == null)? new Command("Ctrl", Command.OK,2) :ctrlCmd;
        return ctrlCmd;
    }
    
    public Command getAltCmd(){
        altCmd = (altCmd == null)? new Command("Alt", Command.OK,2) :altCmd;
        return altCmd;
    }
    
    public Command getDisconnectCmd(){
        disconnectCmd = (disconnectCmd == null)? new Command("Disconnect", Command.OK,2) :disconnectCmd;
        return disconnectCmd;
    }
    
    public Form getInputForm(){
        if(inputForm == null){
            inputForm = new Form(null, new Item[] {
                getInputFormTF() });
        }
        inputForm.addCommand(getInputFormExitCmd());
        inputForm.addCommand(getInputFormSendCmd());
        inputForm.setCommandListener(this);
        return inputForm;
    }
    public Command getInputFormExitCmd(){
        inputFormExitCmd = (inputFormExitCmd == null)? new Command("EXIT",Command.EXIT,1):inputFormExitCmd;
        return inputFormExitCmd;
    }
    public Command getInputFormSendCmd(){
        inputFormSendCmd = (inputFormSendCmd == null)? new Command("SEND",Command.OK,1):inputFormSendCmd;
        return inputFormSendCmd;
    }
    public TextField getInputFormTF(){
        inputFormTF = (inputFormTF == null)? new TextField("Input", null, 120, TextField.ANY) : inputFormTF;
        return inputFormTF;
    }
    
    public Form getCtrlForm(){
        if(ctrlForm == null){
            ctrlForm = new Form(null, new Item[] {
                getCtrlFormTF() });
        }
        ctrlForm.addCommand(getCtrlFormExitCmd());
        ctrlForm.addCommand(getCtrlFormSendCmd());
        ctrlForm.setCommandListener(this);
        return ctrlForm;
    }
    public Command getCtrlFormExitCmd(){
        ctrlFormExitCmd = (ctrlFormExitCmd == null)? new Command("EXIT",Command.EXIT,1):ctrlFormExitCmd;
        return ctrlFormExitCmd;
    }
    public Command getCtrlFormSendCmd(){
        ctrlFormSendCmd = (ctrlFormSendCmd == null)? new Command("SEND",Command.OK,1):ctrlFormSendCmd;
        return ctrlFormSendCmd;
    }
    public TextField getCtrlFormTF(){
        ctrlFormTF = (ctrlFormTF == null)? new TextField("Ctrl", null, 120, TextField.ANY) : ctrlFormTF;
        return ctrlFormTF;
    }
    public Form getAltForm(){
        if(altForm == null){
            altForm = new Form(null, new Item[] {
                getAltFormTF() });
        }
        altForm.addCommand(getAltFormExitCmd());
        altForm.addCommand(getAltFormSendCmd());
        altForm.setCommandListener(this);
        return ctrlForm;
    }
    public Command getAltFormExitCmd(){
        altFormExitCmd = (altFormExitCmd == null)? new Command("EXIT",Command.EXIT,1):altFormExitCmd;
        return altFormExitCmd;
    }
    public Command getAltFormSendCmd(){
        altFormSendCmd = (altFormSendCmd == null)? new Command("SEND",Command.OK,1):altFormSendCmd;
        return altFormSendCmd;
    }
    public TextField getAltFormTF(){
        altFormTF = (altFormTF == null)? new TextField("Alt", null, 120, TextField.ANY) : altFormTF;
        return altFormTF;
    }
    
    public void commandAction(Command command, Displayable displayable){
        try {
            if(displayable == this){
                if(command == inputCmd){
                    this.getInputFormTF().setString("");
                    gui.getDisplay().setCurrent(getInputForm());
                }else if(command == key_EnterCmd){
                    sendCmd('\r');
                }else if(command == exitCmd){
                    gui.exitMIDlet();
                }else if(command == key_BackSpaceCmd){
                    sendCmd((char)0x7F);
                }else if(command == spaceCmd){
                    sendCmd((char)0x32);
                }else if(command == backspaceCmd){
                    sendCmd((char)0x08);
                }else if(command == tabCmd){
                    
                }else if(command == delCmd){
                    
                }else if(command == page_upCmd){
                    sendCmd(new byte[]{0x1B, 0x5B, 0x36, 0x7e});
                }else if(command == page_downCmd){
                    sendCmd(new byte[]{0x1B, 0x5B, 0x35, 0x7e});
                }else if(command == ctrlCmd){
                    if(ctrlFormTF != null)
                        ctrlFormTF.setString("");
                    gui.getDisplay().setCurrent(getCtrlForm());
                }else if(command == altCmd){
                    if(altFormTF != null)
                        altFormTF.setString("");
                    gui.getDisplay().setCurrent(getAltForm());
                }else if(command == disconnectCmd){
                    switch(protocol){
                        case 0:
                            break;
                        case 1:
                            ansi.pushChars("Please waiting for the connection until it has been terminated\r\n".toCharArray());
                            ssh.terminateConnection();
                            while(ssh.connectionAlive());
                            break;
                    }
                    gui.getDisplay().setCurrent(gui.get_hostList());
                }
            }else if(displayable == inputForm){
                if(command == inputFormExitCmd){
                    gui.getDisplay().setCurrent(this);
                    this.repaint();
                }else{
                    sendCmd();
                    gui.getDisplay().setCurrent(this);
                }
            }else if(displayable == sshLogin){
                if(command == okCommand7){
                    hostInfo.setPwd(get_sshLogin_pwdTF().getString());
                    hostInfo.save();
                    gui.getDisplay().setCurrent(this);
                    this.repaint();
                    synchronized(sshIO){
                        sshIO.notifyAll();
                    }
                }
            }else if(displayable == ctrlForm){
                if(command == ctrlFormExitCmd){
                    gui.getDisplay().setCurrent(this);
                }else{
                    char c = (char)ctrlFormTF.getString().charAt(0);
                    switch(c){
                        case ascii_P:
                            sendCmd((char)0x10);
                            break;
                        case ascii_p:
                            sendCmd((char)0x10);
                            break;
                        case ascii_x:
                            sendCmd((char)0x18);
                            break;
                        case ascii_X:
                            sendCmd((char)0x18);
                            break;
                        case ascii_c:
                            sendCmd((char)0x03);
                            break;
                        case ascii_C:
                            sendCmd((char)0x03);
                            break;
                            
                    }
                    gui.getDisplay().setCurrent(this);
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    public void setSshIOinstance(SshIO sshIO){
        this.sshIO = sshIO;
    }
    
    private void sendCmd() throws IOException{
        if(protocol == 0){
            if(telnet.connectionAlive()){
                telnet.sendCmd(getInputFormTF().getString().getBytes());
            }else{
            }
        }else if (protocol == 1){
            if(ssh.connectionAlive()){
                if(!inputLock){
                    gui.getDisplay().setCurrent(this);
                    int temp = Thread.currentThread().getPriority();
                    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                    while(!inputLock);
                    Thread.currentThread().setPriority(temp);
                }
                ssh.sendChannelData(getInputFormTF().getString());
            }
        }
    }
    private void sendCmd(String cmd){
        switch(protocol){
            case 0:
                if(telnet.connectionAlive())
                    telnet.sendCmd(cmd.getBytes());
                break;
            case 1:
                try {
                    ssh.sendChannelData(cmd);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                break;
        }
    }
    private void sendCmd(byte[] cmd){
        switch(protocol){
            case 0:
                if(telnet.connectionAlive())
                    telnet.sendCmd(cmd);
                break;
            case 1:
                try {
                    ssh.sendChannelData(new String(cmd));
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                break;
        }
    }
    private void sendCmd(char cmd){
        switch(protocol){
            case 0:
                if(telnet.connectionAlive()){
                    telnet.sendCmd(new byte[]{(byte)cmd});
                }
                break;
            case 1:
                try {
                    ssh.sendChannelData(cmd+"");
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                break;
        }
        
    }
    
    public void setGUI(GUI gui){
        this.gui = gui;
    }
    
    protected void keyPressed(int keyCode){
        /** WTK 2.5.1 simulator:
         *                   up: -1
         *                 down: -2
         *                 left: -3
         *                right: -4
         */
        
        switch(keyCode){
            case KEY_RIGHT:
                basePosX += 5;
                this.repaint();
                break;
            case KEY_LEFT:
                basePosX = (basePosX == 0)? 0 : basePosX - 5;
                this.repaint();
                break;
            case KEY_UP:
                basePosY = (basePosY > 0)? basePosY - 1 : 0 ;
                this.repaint();
                break;
            case KEY_DOWN:
                basePosY += 1;
                this.repaint();
                break;
            case KEY_NUM0:
                sendCmd(new byte[]{0x7F, 0x7F});
                this.repaint();
                break;
            case KEY_NUM1:
                sendCmd('\r');
                this.repaint();
                break;
            case KEY_NUM2:
                sendCmd((char)0x1b);
                sendCmd('O');
                sendCmd('A');
                this.repaint();
                break;
            case KEY_NUM3:
                sendCmd(new byte[]{0x1B, 0x5B, 0x35, 0x7e});
                break;
            case KEY_NUM4:
                sendCmd((char)0x1b);
                sendCmd('O');
                sendCmd('D');
                this.repaint();
                break;
            case KEY_NUM5:
                sendCmd((char)0x1b);
                sendCmd('O');
                sendCmd('B');
                this.repaint();
                break;
            case KEY_NUM6:
                sendCmd((char)0x1b);
                sendCmd('O');
                sendCmd('C');
                this.repaint();
                break;
            case KEY_NUM7:
                break;
            case KEY_NUM8:
                this.getInputFormTF().setString("");
                gui.getDisplay().setCurrent(getInputForm());
                break;
            case KEY_NUM9:
                sendCmd(new byte[]{0x1B, 0x5B, 0x36, 0x7e});
                break;
            case KEY_POUND:
                sendCmd(new byte[]{0x1B, 0x5B, 0x33, 0x7e});
                this.repaint();
                break;
        }
    }
    
    public int getProtocol() {
        return protocol;
    }
    
    public void setProtocol(int protocol) {
        this.protocol = protocol;
    }
    
    public void pwdReEnter(HostInfoData hostInfo){
        this.hostInfo = hostInfo;
        gui.getDisplay().setCurrent(get_sshLogin());
    }
    
    public Form get_sshLogin() {
        if (sshLogin == null) {
            // Insert pre-init code here
            sshLogin = new Form(null, new Item[] {
                get_sshLogin_pwdTF()
            });
            sshLogin.addCommand(get_sshLogin_backCmd());
            sshLogin.addCommand(get_okCommand7());
            sshLogin.setCommandListener(this);
        }
        return sshLogin;
        
    }
    
    /** This method returns instance for sshLogin_pwdTF component and should be called instead of accessing sshLogin_pwdTF field directly.
     * @return Instance for sshLogin_pwdTF component
     */
    public TextField get_sshLogin_pwdTF() {
        if (sshLogin_pwdTF == null) {
            // Insert pre-init code here
            sshLogin_pwdTF = new TextField("Password", null, 120, TextField.ANY | TextField.PASSWORD);
            // Insert post-init code here
        }
        return sshLogin_pwdTF;
    }
    /** This method returns instance for sshLogin_backCmd component and should be called instead of accessing sshLogin_backCmd field directly.
     * @return Instance for sshLogin_backCmd component
     */
    public Command get_sshLogin_backCmd() {
        if (sshLogin_backCmd == null) {
            // Insert pre-init code here
            sshLogin_backCmd = new Command("\u4E0A\u4E00\u9801", Command.BACK, 1);
            // Insert post-init code here
        }
        return sshLogin_backCmd;
    }
    /** This method returns instance for okCommand7 component and should be called instead of accessing okCommand7 field directly.
     * @return Instance for okCommand7 component
     */
    public Command get_okCommand7() {
        if (okCommand7 == null) {
            // Insert pre-init code here
            okCommand7 = new Command("\u78BA\u5B9A", Command.OK, 0);
            // Insert post-init code here
        }
        return okCommand7;
    }
}



